package com.imooc.distributedemo.resume.thread;

import java.util.concurrent.atomic.AtomicInteger;

public class VolatileTest {
    volatile int number = 0;

    public void increase(){
        number ++;
    }

    public static void main(String[] args) {
        VolatileTest volatileDemo = new VolatileTest();
        for (int i = 0; i < 10; i++) {
            new Thread(()->{
                for (int j = 0; j < 1000; j++) {
                    volatileDemo.increase();
                }
            },String.valueOf(i)).start();
        }
        while (Thread.activeCount() > 2){
            Thread.yield();
        }
        System.out.println(Thread.currentThread().getName()+" --- "
                +volatileDemo.number);

        AtomicInteger integer = new AtomicInteger();
        integer.incrementAndGet();
    }
}
